﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;

using System.Text;
using System.Collections;
using System.Windows.Forms;

using MathNet.Numerics.Statistics;

namespace Quality.spc
{
    public partial class basicAnalysis : Form
    {
        DataTable dt;
        public basicAnalysis()
        {
            InitializeComponent();
            this.dataGridView1.AutoGenerateColumns = false;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            getdata frm = new getdata();

            frm.WindowState = FormWindowState.Normal;
            frm.Dock = DockStyle.Fill;
            frm.TransfEventdt += frm_TransfEventdt;
            frm.StartPosition = FormStartPosition.CenterParent;

            frm.Show();
        }
        //事件处理方法
        void frm_TransfEventdt(DataTable value)
        {
            dataGridView1.DataSource = value;
            this.dt = value;
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            var data = new double[dt.Rows.Count];
            for (var i = 0; i < data.Length; i++)
            {
                data[i] =Convert.ToDouble(dt.Rows[i]["testvalue"]);
            }

           // Double[] data = dt.AsEnumerable().Select(d => d.Field<Double>("testvalue")).ToArray();

           
            label1.Text = " 最大值:" + data.Maximum().ToString(" #0.00000;-#0.00000") + "\n\r\n\r";
            label1.Text = label1.Text + " 最小值:" + data.Minimum().ToString(" #0.00000;-#0.00000") + "\n\r\n\r";
            label1.Text = label1.Text + " 均值:" + data.Mean().ToString(" #0.00000;-#0.00000") + "\n\r\n\r";
            label1.Text = label1.Text + " 中间值:" + data.Median().ToString(" #0.00000;-#0.00000") + "\n\r\n\r";
            label1.Text = label1.Text + " 有偏方差:" + data.PopulationVariance().ToString(" #0.00000;-#0.00000") + "\n\r\n\r";
            label1.Text = label1.Text + " 无偏方差:" + data.Variance().ToString(" #0.00000;-#0.00000") + "\n\r\n\r";
            label1.Text = label1.Text + " 标准偏差:" + data.StandardDeviation().ToString(" #0.00000;-#0.00000") + "\n\r\n\r";
            label1.Text = label1.Text + " 标准有偏偏差:" + data.PopulationStandardDeviation().ToString(" #0.00000;-#0.00000") + "\n\r\n\r";

            

        }
    }
}
